package all.com.jinyongqunxiax.modules;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.randy.fundation.JxFunc;
import com.randy.fundation.Logger;

import all.com.jinyongqunxiax.R;
import all.com.jinyongqunxiax.component.JxForm;
import all.com.jinyongqunxiax.component.JxFormHeader;
import all.com.jinyongqunxiax.component.JxFormItemImage;
import all.com.jinyongqunxiax.component.JxFormItemText;
import all.com.jinyongqunxiax.databinding.SkillExternalDetailActivityBinding;
import all.com.jinyongqunxiax.model.mod.SkillsExternalManager;
import all.com.jinyongqunxiax.model.mod.manager.Mod;
import all.com.jinyongqunxiax.model.mod.manager.ModManager;
import all.com.jinyongqunxiax.view.JxHud;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import jy.game.components.wuxue.JyTrigger;
import jy.game.components.wuxue.pojo.JySkill;
import jy.game.components.wuxue.pojo.JyUniqueSkill;

public class SkillExternalDetailActivity extends AppCompatActivity {
    private Options                            options;
    private SkillExternalDetailActivityBinding binding;
    JxForm form = new JxForm();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        options = new Options(getIntent());

        setTitle(options.item);

        Mod                   mod     = ModManager.shared().get(options.mod);
        SkillsExternalManager manager = mod.skillsExternalManager;
        JySkill               model   = manager.map.get(options.item);

        binding = DataBindingUtil.setContentView(this, R.layout.skill_external_detail_activity);

        RecyclerView recyclerView = binding.recyclerView;
        form.connect(this, recyclerView);

        if (model != null) {
            form.add(new JxFormHeader(0, "基本信息", null));

            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("名称").value("" + model.name).hint("name").value(), null));

            String imagePath = mod.imagePath(model.icon);
            form.add(new JxFormItemImage(0, "图标", imagePath));

            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("信息").value(model.info).hint("info").value(), null));

            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("动画").value(model.animation).hint("animation").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("音效").value(model.audio).hint("audio").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("基础攻击").value("" + model.basePower).hint("basepower").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("增益").value(model.buff).hint("buff").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build().label("冷却").value("" + model.coolDown).hint("cd").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("hard", "" + model.hard).hint("hard").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("STEP", "" + model.step).hint("STEP").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("suit", "" + model.suit).hint("suit").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("调和", "" + model.tiaoheValue).hint("tiaohe").value(), null));
            form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("类型", "" + model.type).hint("type").value(), null));

            form.add(new JxFormHeader(0, "效果", null));

            JxFunc.of(model.triggers).ifPresent(new JxFunc.Action<JyTrigger>() {
                @Override
                public void yield(@NonNull JyTrigger trigger) {
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build(trigger.name, trigger.argvsValue + " " + trigger.level).hint("").value(), null));
                }
            });

            JxFunc.of(model.uniqueSkills).ifPresent(new JxFunc.Action<JyUniqueSkill>() {
                @Override
                public void yield(@NonNull JyUniqueSkill unique) {

                    form.add(new JxFormHeader(0, "奥义:" + unique.name, null));
                    String imagePath = mod.imagePath(unique.icon);
                    form.add(new JxFormItemImage(0, "图标", imagePath));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("增益", unique.buffsValue).hint("buff").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("信息", unique.info).hint("info").value(), null));

                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("动画", unique.animation).hint("animation").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("音效", unique.audio).hint("audio").value(), null));

                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("冷却", "" + unique.castCd).hint("cd").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("hard", "" + unique.hard).hint("hard").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("castsize", "" + unique.castSize).hint("castsize").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("costball", "" + unique.costBall).hint("costball").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("coversize", "" + unique.coverSize).hint("coversize").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("covertype", "" + unique.coverType).hint("covertype").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("poweradd", "" + unique.powerAdd).hint("poweradd").value(), null));
                    form.add(new JxFormItemText(0, JxForm.TextField.Builder.build("requirelv", "" + unique.requireLevel).hint("requirelv").value(), null));
                }
            });
        }
        form.refresh();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.plus_button_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_add_button:
                JxHud.info("add menu clicked");
                break;
            default:
                Logger.w("not handle menu %d", item.getItemId());
                break;
        }
        return true;
    }

    public static class Options {
        String mod;
        String item;

        Options(Intent intent) {
            this.mod = intent.getStringExtra("mod");
            this.item = intent.getStringExtra("item");
        }

        static Intent intent(Context context, String mod, String item) {
            Intent intent = new Intent(context, SkillExternalDetailActivity.class);
            intent.putExtra("mod", mod);
            intent.putExtra("item", item);
            return intent;
        }
    }
}
